package com.ruoyi.sms.domain.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;

/**
 * @Author: WangYue
 * @Description:
 * @Date: 2021-06-03 10:44
 */
@Slf4j
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class DewinSendSmsResponse implements Serializable {
    private String requestId;
    private String message;
    private String bizId;
    private String code;

    public static DewinSendSmsResponse dh3tDewinSendSmsResponse(Dh3tSendSmsResponse dh3tSendSmsResponse) {
        try {
            DewinSendSmsResponse dewinSendSmsResponse = new DewinSendSmsResponse();
            dewinSendSmsResponse.setRequestId(dh3tSendSmsResponse.getResult());
            dewinSendSmsResponse.setMessage(dh3tSendSmsResponse.getDesc());
            dewinSendSmsResponse.setBizId(dh3tSendSmsResponse.getMsgid());
            dewinSendSmsResponse.setCode("0".equals(dh3tSendSmsResponse.getResult()) ? "0" : "1");
            return dewinSendSmsResponse;
        } catch (Exception e) {
            log.error("dh3tDewinSendSmsResponse 发生错误,{}", e.getMessage());
            return failureResponse();
        }
    }

    public static DewinSendSmsResponse failureResponse() {
        return DewinSendSmsResponse.builder().bizId("").code("1").message("发送失败").requestId("").build();
    }

    public boolean sendSuccess() {
        return this.getCode().equals("0");
    }
}
